<script type="text/javascript">
	var urlParams = (function(url){
		var result = new Object();
		var idx = url.lastIndexOf('?');
		if (idx > 0){
			var params = url.substring(idx + 1).split('&');
			for (var i = 0; i < params.length; i++){
				idx = params[i].indexOf('=');
				if (idx > 0){
					result[params[i].substring(0, idx)] = params[i].substring(idx + 1);
				}
			}
		}
		return result;
	})(window.location.href);
	mxLoadResources = false;
	mxBasePath = _contextPath + '/dacp-res/js/mxGraphEditor';
	STENCIL_PATH  = _contextPath + '/dacp-view/datastash/unit_creator/images/step';
</script>

<script src="${mvcPath}/dacp-lib/snap/snap.svg-min.js"></script>
<script src="${mvcPath}/dacp-res/js/fileSaver.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Init.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/jscolor/jscolor.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/sanitizer/sanitizer.min.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-lib/mxGraph/mxClient.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/EditorUi.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Editor.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Sidebar.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Graph.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Shapes.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Actions.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Menus.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Format.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Toolbar.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Dialogs.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-res/js/mxGraphEditor/js/Event.js"></script>
<script src="${mvcPath}/dacp-res/js/json_format.js"></script>
<script type="text/javascript" src="${mvcPath}/dacp-view/datastash/workshop/unit_creator/js/step_define.js"></script>

<script>
var graphEditorUrl = _contextPath + '/dacp-res/js/mxGraphEditor/',
    editorUi,
    initEditor = function(mainVue, graphXml) {
		var editorUiInit = EditorUi.prototype.init;
		EditorUi.prototype.init = function(){
			editorUiInit.apply(this, arguments);
			this.actions.get('export').setEnabled(false);
		};
		mxResources.loadDefaultBundle = false;
		var bundle = mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) || mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage);
		
		mxUtils.getAll([graphEditorUrl+bundle, graphEditorUrl+STYLE_PATH + '/default.xml'], function(xhr){
			mxResources.parse(xhr[0].getText());
			var themes = new Object();
			themes[Graph.prototype.defaultThemeName] = xhr[1].getDocumentElement(); 
			editorUi = new EditorUi(new Editor(urlParams['chrome'] == '0', themes, null, null, 0, {}, mainVue.model), document.getElementById("graphEditor"));
	        $('.geSidebarContainer').width('180px');
	        mainVue.expandSidebar();
	        window.getStepDefine();

	        editorUi.editor.graph.model.addListener(mxEvent.NOTIFY, function() {
	        	var map = editorUi.editor.graph.view.states.map;
	        	for(var i = 0; i < mainVue.tabData.length; i++) {
	        		if (!map[mainVue.tabData[i].name]) {
	        			mainVue.tabData.splice(i, 1);
	        			i--;
	        		}
	        	}
	        });
        	
	        setTimeout(function() {
	        	editorUi.refresh();
		        if (graphXml) {
	        		store.commit('renderGraphXml', graphXml);
	        	}
	        },100)
			}, 
			function(){
			    document.body.innerHTML = '<center style="margin-top:10%;">Error loading resource files. Please check browser console.</center>';
		    }
		);
	};

</script>